package test3.backtracking;

import java.util.ArrayList;
import java.util.List;

/**
 * 401. 二进制手表
 * 二进制手表顶部有 4 个 LED 代表 小时（0-11），底部的 6 个 LED 代表 分钟（0-59）。每个 LED 代表一个 0 或 1，最低位在右侧。
 */
public class ReadBinaryWatch {
    private List<String> res = new ArrayList<>();
    public List<String> readBinaryWatch(int turnedOn) {
        int[] book = new int[10];
        dfs(turnedOn, 0, book);
        return res;
    }

    private void dfs(int nums, int cur, int[] book) {
        if (nums == 0) {
            int hour = 8 * book[0] + 4 * book[1] + 2 * book[2] + book[3];
            int minute = 32 * book[4] + 16 * book[5] + 8 * book[6] + 4 * book[7] + 2 * book[8] + book[9];
            if (hour < 12 && minute < 60) {
                res.add(String.format("%d:%02d", hour, minute));
            }
            return;
        }
        for (int i = cur; i < 10; i++) {
            book[i] = 1;
            dfs(nums - 1, i + 1, book);
            book[i] = 0;
        }
    }

    public static void main(String[] args) {
        List<String> list = new ReadBinaryWatch().readBinaryWatch(2);
        for (String s : list) {
            System.out.println(s);
        }
    }
}
